package regex;


import java.util.regex.Matcher;
import sun.jvm.hotspot.utilities.AssertionFailure;


/**
 * Description.
 *
 * @author panda
 */
public class SJPatternTest3 {

    public void test(){
        //1.带有协议测试
        //1.1 中文
        //1.2 英文
        //1.3 有端口
        //1.4 没有端口
        //1.5 ip
        //1.6 ip带有端口
        //1.7 没有端口
        //2. 没有协议测试（同上）

        assertEquals(true, Patterns.WEB_URL.matcher("http://我是pinduoduo.com.cn").find());
        assertEquals(true, Patterns.WEB_URL.matcher("http://www.pinduoduo.com").find());
        assertEquals(true, Patterns.WEB_URL.matcher("Http://www.pinduoduo.com").find());
        assertEquals(true, Patterns.WEB_URL.matcher("HtTp://www.pinduoduo.com").matches());
        assertEquals(true, Patterns.WEB_URL.matcher("http://www.pinduoduo.com:8080").find());
        assertEquals(true, Patterns.WEB_URL.matcher("https://www.xin.xin:8080").matches());


        assertEquals(true, Patterns.WEB_URL.matcher("http://192.168.1.1").find());
        assertEquals(false, Patterns.WEB_URL.matcher("http://300.300.1.1:8080").find());
        assertEquals(false, Patterns.WEB_URL.matcher("http://中国.美国.英国").find());


        assertEquals(true, Patterns.WEB_URL.matcher("我是pinduoduo.com.cn").find());
        assertEquals(false, Patterns.WEB_URL.matcher("我是pinduoduo.com.cn").matches());

        assertEquals(true, Patterns.WEB_URL.matcher("www.pinduoduo.com").find());
        assertEquals(true, Patterns.WEB_URL.matcher("www.pinduoduo.com").matches());

        assertEquals(true, Patterns.WEB_URL.matcher("www.pinduoduo.com:8080").find());

        assertEquals(true, Patterns.WEB_URL.matcher("www.xin.xin:8080").find());
        assertEquals(true, Patterns.WEB_URL.matcher("www.xin.xin:8080").matches());

        assertEquals(false, Patterns.WEB_URL.matcher("中国.美国.英国").find());


        assertEquals(true, Patterns.WEB_URL.matcher("192.168.1.1").find());
        assertEquals(false, Patterns.WEB_URL.matcher("300.300.1.1:8080").find());

        assertEquals(false, Patterns.WEB_URL.matcher("1.我不是url啊").find());
        
        assertEquals(true, Patterns.WEB_URL.matcher("123@345.com").find());
        assertEquals(false, Patterns.WEB_URL.matcher("123@345.com").matches());


        assertEquals(true, Patterns.WEB_URL.matcher("345.com").find());
        assertEquals(true, Patterns.WEB_URL.matcher("pinduoduo.com").find());

        assertEquals(false, Patterns.WEB_URL.matcher("美国@中国.com").find());

        assertEquals(false, Patterns.WEB_URL.matcher("我不是hahah美国@中国.com").find());
        assertEquals(false, Patterns.WEB_URL.matcher("我不是hahah美国@中国.com").find());

        assertEquals(true, Patterns.WEB_URL.matcher("您好, 关于您反馈的问题,请问在哪里白屏呢,麻烦再链接https://h5.pinduoduo.com/feedback/index.html$中提供截图并详细说明哦.感谢您对knock的支持!").find());
        assertEquals(true, Patterns.WEB_URL.matcher("您好，风润，您于2019-09-22 10:54:05 打卡成功，若要关闭打卡提醒，可点击https://oa.pdd.net/apply?calendar=open关闭“打卡邮件提醒!").find());
        assertEquals(false, Patterns.WEB_URL.matcher("我怎么感觉点knock ios的图标，有的时候，感觉会卡个0.x秒，大家有碰到这个情况不？").find());


        String realUrl = "https://h5.pinduoduo.com/feedback/index.html";
        String url = "您好, 关于您反馈的问题,请问在哪里白屏呢,麻烦再链接"+realUrl+"中提供截图并详细说明哦.感谢您对knock的支持!";
        Matcher matcher = Patterns.WEB_URL.matcher(url);
        assertEquals(true, matcher.find());
        assertEquals(realUrl, matcher.group(0));
    }

    public static void assertEquals(boolean src, boolean dest) {
       if (src != dest) {
           throw new AssertionFailure("");
       }
    }

    public static void assertEquals(String src, String dest) {
        if (!src.equals(dest)) {
            throw new AssertionFailure("");
        }
    }
}
